# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter


class Duanzi01Pipeline:
    f = None
    def open_spider(self, spider):
        print('爬虫开始时被调用一次')
        self.f = open('./duanzi.txt', 'w')

    def process_item(self, item, spider):
        print(item)
        self.f.write(item['title'] + item['con'] + '\n')
        return item

    def close_spider(self, spider):
        print('爬虫结束时被调用')
        self.f.close()
